home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / VirtualLight / VLight1.3win32.exe / VibSDK / Samples / sample7.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-07  |  5.0 KB  |  107 lines

  1. /*
  2.  * VirtuaLight's binary .VIB format API, sample 5
  3.  * Written by Stephane Marty, 09/26/2001
  4.  *
  5.  * This sample program writes a binary VIB file
  6.  * describing a simple NURBS sphere.
  7.  */
  8.  
  9. #include "..\vlBinDef.h"
  10.  
  11. #ifdef WIN32
  12. #pragma warning( disable : 4305 )
  13. #endif
  14.  
  15. #define U_PTS 7
  16. #define U_ORD 4
  17. #define V_PTS 11
  18. #define V_ORD 4
  19.  
  20. // The following data define a nurbs sphere
  21. viDBL knU[U_PTS+U_ORD] = { 0.0, 0.0, 0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0 };
  22. viDBL knV[V_PTS+V_ORD] = { -0.25, -0.25, -0.125, 0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.25 };
  23. viVECTOR CPoints[U_PTS][V_PTS] = {
  24.     { {0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000},{0.000000, 0.893874, 0.000000} },
  25.     { {0.506728, 0.893874, 0.506728},{0.716622, 0.893874, 0.000000},{0.506728, 0.893874, -0.506728},{0.000000, 0.893874, -0.716622},{-0.506728, 0.893874, -0.506728},{-0.716622, 0.893874, 0.000000},{-0.506728, 0.893874, 0.506728},{0.000000, 0.893874, 0.716622},{0.506728, 0.893874, 0.506728},{0.716622, 0.893874, 0.000000},{0.506728, 0.893874, -0.506728} },
  26.     { {1.562462, 1.442352, 1.562462},{2.209655, 1.442352, 0.000000},{1.562462, 1.442352, -1.562462},{0.000000, 1.442352, -2.209655},{-1.562462, 1.442352, -1.562462},{-2.209655, 1.442352, 0.000000},{-1.562462, 1.442352, 1.562462},{0.000000, 1.442352, 2.209655},{1.562462, 1.442352, 1.562462},{2.209655, 1.442352, 0.000000},{1.562462, 1.442352, -1.562462} },
  27.     { {2.198094, 3.428569, 2.198094},{3.108574, 3.428569, 0.000000},{2.198094, 3.428569, -2.198094},{0.000000, 3.428569, -3.108574},{-2.198094, 3.428569, -2.198094},{-3.108574, 3.428569, 0.000000},{-2.198094, 3.428569, 2.198094},{0.000000, 3.428569, 3.108574},{2.198094, 3.428569, 2.198094},{3.108574, 3.428569, 0.000000},{2.198094, 3.428569, -2.198094} },
  28.     { {1.562462, 5.414785, 1.562462},{2.209655, 5.414785, 0.000000},{1.562462, 5.414785, -1.562462},{0.000000, 5.414785, -2.209655},{-1.562462, 5.414785, -1.562462},{-2.209655, 5.414785, 0.000000},{-1.562462, 5.414785, 1.562462},{0.000000, 5.414785, 2.209655},{1.562462, 5.414785, 1.562462},{2.209655, 5.414785, 0.000000},{1.562462, 5.414785, -1.562462} },
  29.     { {0.506728, 5.963264, 0.506728},{0.716622, 5.963264, 0.000000},{0.506728, 5.963264, -0.506728},{0.000000, 5.963264, -0.716622},{-0.506728, 5.963264, -0.506728},{-0.716622, 5.963264, 0.000000},{-0.506728, 5.963264, 0.506728},{0.000000, 5.963264, 0.716622},{0.506728, 5.963264, 0.506728},{0.716622, 5.963264, 0.000000},{0.506728, 5.963264, -0.506728} },
  30.     { {0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000},{0.000000, 5.963264, 0.000000} }
  31. };
  32.  
  33. void main(void)
  34. {
  35.     viNURBS            *nurbs;
  36.     viCAMERA        *cam;
  37.     viGENERAL        *gen;
  38.     viSHAPE_MODIFIERS    *sm;
  39.     viPOINT_LIGHT    *pl;
  40.     viFILE            *vib;
  41.     viINT i, j;
  42.    
  43.     // Open a new VIB file
  44.     vib = viNewBinaryVIB("sample7.vib");
  45.  
  46.     // Add the camera (low adaptive antialiasing enabled)
  47.     cam = viNewCamera();
  48.     viSetInt(cam->Format.X, 256);
  49.     viSetInt(cam->Format.Y, 256);
  50.     viSetDbl(cam->FrameAspectRatio, 1.0);
  51.     viSetVector(&cam->Location, 2, 5, -10);
  52.     viSetVector(&cam->LookAt, 0, 3, 1);
  53.     viSetVector(&cam->UpAxis, 0, 1, 0);
  54.     viSetDbl(cam->FieldOfView, 40);
  55.     viSetInt(cam->Antialiasing, 1);
  56.     viDumpCamera(cam, vib);
  57.     free(cam);
  58.  
  59.     // Set the background color
  60.     gen = viNewGeneral();
  61.     viSetColor(&gen->Background, 0.098039*2, 0.098039*2, 0.392157*2);
  62.     viDumpGeneral(gen, vib);
  63.     free(gen);
  64.  
  65.     // Add two pointlights
  66.     pl = viNewPointLight();
  67.     viSetColor(&pl->Intensity, 0.6, 0.6, 0.6);
  68.     viSetVector(&pl->Position, 5, 15, -15);
  69.     viDumpPointLight(pl, vib);
  70.     viSetColor(&pl->Intensity, 0.6, 0.6, 0.6);
  71.     viSetVector(&pl->Position, -20, 25, -20);
  72.     viDumpPointLight(pl, vib);
  73.     free(pl);
  74.  
  75.     /*
  76.      * create the NURBS (nu=7, uorder=4, nv=11, vorder=4)
  77.      */
  78.     nurbs = viNewNURBS(U_PTS, U_ORD, V_PTS, V_ORD);
  79.     for (i=0; i<nurbs->nuknots; i++)
  80.         nurbs->uknot[i] = knU[i];
  81.     for (i=0; i<nurbs->nvknots; i++)
  82.         nurbs->vknot[i] = knV[i];
  83.     for (i=0;i<nurbs->nu;i++)
  84.         for (j=0;j<nurbs->nv;j++)
  85.             viSetControlPoint(&nurbs->cpoints[i][j],
  86.                 CPoints[i][j].x,
  87.                 CPoints[i][j].y,
  88.                 CPoints[i][j].z);
  89.     // dump the nurbs
  90.     viPrimitive(vib);
  91.     viDumpNURBS(nurbs, vib);
  92.     viPrimitiveShaderName("nurbs_ball", vib);
  93.     sm = viNewShapeModifiers();
  94.     viSetInt(sm->ShapeSubdivisions.u, 14);
  95.     viSetInt(sm->ShapeSubdivisions.v, 22);
  96.     viSetDbl(sm->RenderBound.umin, 0.0);
  97.     viSetDbl(sm->RenderBound.vmin, 0.0);
  98.     viSetDbl(sm->RenderBound.umax, 1.0);
  99.     viSetDbl(sm->RenderBound.vmax, 1.0);
  100.     viDumpShapeModifiers(sm, vib);
  101.     viEndPrimitive(vib);
  102.     viDeleteNURBS(nurbs);
  103.     free(sm);
  104.  
  105.     // Close the VIB file
  106.     viCloseBinaryVIB(vib);    
  107. }